<include file="Common:doc_head"/>
<style>
#tb-type th{
    color: #fff;
    background-color: #555;
    border: 1px solid #555;
    vertical-align: top;
}
#tb-type th,#tb-type td{
    text-align: center;
}
</style>
<div class="container" style="">


    <div class="row" >
        <div class="col-md-12" style="">
            <table id="tb-type" class="table table-bordered table-striped">
                <caption>
                    <button class="btn btn-primary editType" data-id="0" tname="" sort="1">添加分类</button>
                </caption>
                <thead>
                <tr>
                    <th style="width:20%;">分类ID</th>
                    <th style="width: 30%">分类名</th>
                    <th style="width: 30%">排序</th>
                    <th style="width: 20%;">操作</th>
                </tr>
                </thead>
                <tbody>
                <volist name="data" id="d">
                    <tr>
                        <td>{$d.t_id}</td>
                        <td>{$d.t_name}</td>
                        <td>{$d.sort}</td>
                        <td>
                            <a class="editType" data-id="{$d.t_id}" tname="{$d.t_name}" sort="{$d.sort}">编辑</a>
                            <a class="delType" data-id="{$d.t_id}">删除</a>
                        </td>
                    </tr>
                </volist>
                </tbody>
            </table>
        </div>
    </div>

</div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">编辑分类</h4>
            </div>
            <div class="modal-body">
                <label>分类名：</label><input type="text" id="t_name" class="form-control" placeholder="输入分类名"/>
                <label>排序：</label><input type="text" id="sort" class="form-control" placeholder="输入数字"/>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="saveType" data-id="">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>


<script type="text/javascript">
    $(document).ready(function(){
        $('title').text('分类管理【{$pro_name}】');
        //编辑  添加
        $('.editType').click(function () {
            $('#t_name').val($(this).attr('tname'));
            $('#saveType').attr('data-id',$(this).attr('data-id'));
            $('#sort').val($(this).attr('sort'));
            $('#myModal').modal('show');
        });
        //提交分类编辑 添加
        $('#saveType').click(function () {
            var data={
                t_id:$(this).attr('data-id'),
                t_name:$('#t_name').val(),
                sort:$('#sort').val(),
                proid:'{$proid}'
            };
            $('#waiting').show();
            $.post('{:U("Doc/saveType")}',data,function (ret) {
                if(ret.status==200){
                    window.location.reload();
                }else{
                    alert(ret.message);
                }
                $('#waiting').hide();
            },'json');
            $('#myModal').modal('hide');
        });
        //删除分类
        $('.delType').click(function () {
            if(!confirm('确定要删除？')){
                return false;
            }
            $('#waiting').show();
            var thisline=$(this).parent('td').parent('tr');
            $.post('{:U("Doc/delType")}',{t_id:$(this).attr('data-id')},function (ret) {
                if(ret.status==200){
                    thisline.remove();
                }else{
                    alert(ret.message);
                }
                $('#waiting').hide();
            },'json');
        });

    });
</script>

</body>
</html>